package com.adams.custom.page.core.service;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.adams.access.db.bean.DicColumn;
import com.adams.access.db.bean.DicElement;
import com.adams.access.db.bean.DicTable;
import com.adams.core.exception.BusinessException;
import com.adams.custom.page.core.dto.DicColumnDto;

/**
 * 
 * File Name : DicTableService.java
 * 
 * @Description : 数据字典服务接口
 */
public interface DicTableService
{

	/**
	 * Description : 根据表名得到数据库对象
	 * 
	 * @param tablecode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public String getDatabase(String tablecode) throws BusinessException;

	/**
	 * Description : 根据目标表名及关系字段 得到关联表是否在同一个数据库中
	 * 
	 * @param tablecode
	 * @param columncodes
	 * @throws BusinessException
	 * 
	 */
	public boolean isSameDatabase(String tablecode, List<String> columncodes)
			throws BusinessException;

	/**
	 * Description : 判断列表中的表是否在同一个数据库中
	 * 
	 * @param tablecode
	 * @param columncodes
	 * @throws BusinessException
	 * 
	 */
	public boolean isSameDatabase(List<String> tablecodes)
			throws BusinessException;

	/**
	 * 根据tablecode删除数据
	 * 
	 * @param tableCode
	 * @param list
	 */
	@SuppressWarnings("unchecked")
	public void deleteData(String tableCode, List<Map> list)
			throws BusinessException;

	/**
	 * Description : 根据表及字段设置得到具体字段的值
	 * 
	 * @param tableCode
	 * @param columncodes
	 * @param inputMap
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public Object findValueByTableCodeAndColumncodes(String tableCode,
			List<String> columncodes, Map inputMap) throws BusinessException;

	/**
	 * Description : 根据表编码得到此表单一的主键定义
	 * 
	 * @param tablecode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public DicColumn getSinglePkColumnByTablecode(String tablecode)
			throws BusinessException;

	/**
	 * Description : 获得所有表定义
	 * 
	 * @return
	 * 
	 */
	public List<DicTable> findAllDicTable();

	/**
	 * Description : 根据表编码得到表定义
	 * 
	 * @param tablecode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public DicTable getDicTable(String tablecode) throws BusinessException;

	/**
	 * Description : 根据表编码得到字段定义列表
	 * 
	 * @param tablecode
	 * @return
	 * 
	 */
	public List<DicColumn> findDicColumnsByTablecode(String tablecode);

	/**
	 * Description : 根据表编码查询冗余字段定义
	 * 
	 * @param tablecode
	 * @return
	 * 
	 */
	public List<DicColumn> findRddcolumnByTablecode(String tablecode);

	/**
	 * Description : 根据来源数据表编码查询冗余字段定义
	 * 
	 * @param tablecode
	 * @return
	 * 
	 */
	public List<DicColumn> findByRddsourcetablecode(String rddsourcetable);

	/**
	 * Description : 根据表编码及字段编码得到字段定义
	 * 
	 * @param tablecode
	 * @param columncode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public DicColumn getDicColumn(String tablecode, String columncode)
			throws BusinessException;

	/**
	 * Description : 获取最末级字段定义
	 * 
	 * @param tablecode
	 * @param colunmcodes
	 * @return
	 * @throws BusinessException
	 */
	public DicColumn getFinalDicColumn(String tablecode,
			List<String> colunmcodes) throws BusinessException;

	/**
	 * Description : 根据数据项编码得到数据项定义
	 * 
	 * @param elementcode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public DicElement findDicElement(String elementcode)
			throws BusinessException;

	/**
	 * Description : 根据elementcode查询数据项数据
	 * 
	 * @param elementcode
	 * @param columns
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Map> getElementsByElementCode(String elementcode,
			Set<String> columns) throws BusinessException;

	/**
	 * Description : 根据表定义，要显示的字段定义列表，查询表别名，过滤条件 构建完整洁的sql查询语句
	 * 
	 * @param dicTable
	 * @param dicColumns
	 * @param dbalias
	 * @param whereSql
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public String buildSearchSql(DicTable dicTable, List<DicColumn> dicColumns,
			String dbalias, String whereSql, List<DicColumn> orderDicColumns)
			throws BusinessException;

	/**
	 * Description : 根据表定义及要显示的字段动态查询部分数据
	 * 
	 * @param dicTable
	 * @param dicColumns
	 * @param start
	 * @param limit
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Map> findData(DicTable dicTable, List<DicColumn> dicColumns,
			int start, int limit) throws BusinessException;

	/**
	 * Description : 根据表定义及要显示的字段动态查询全部数据
	 * 
	 * @param tablecode
	 * @param dicColumns
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Map> findAllData(String tablecode, List<DicColumn> dicColumns)
			throws BusinessException;

	/**
	 * Description : 根据表编码 查询别名 查询sql得到记录个数
	 * 
	 * @param selectCountSql
	 * @return
	 * 
	 */
	public int getCount(String tablecode, String dbalias, String whereSql)
			throws BusinessException;

	/**
	 * Description : 根据要显示的字段定义 查询sql 开始位置 查询条数 查询数据
	 * 
	 * @param dicColumns
	 * @param sql
	 * @param start
	 * @param limit
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Map> findData(String tableCode,
			List<DicColumnDto> dicColumnDtos, String sql, int start, int limit)
			throws BusinessException;

	/**
	 * Description : 根据表结构动态增加数据
	 * 
	 * @param tablecode
	 * @param inputMap
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public Map saveData(String tablecode, Map inputMap)
			throws BusinessException;

	/**
	 * Description : 根据表结构动态批量增加数据
	 * 
	 * @param tablecode
	 * @param inputMap
	 * @return
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Map> saveDatas(String tablecode, List<Map> inputMaps)
			throws BusinessException;

	/**
	 * Description : 根据表结构动态更新数据
	 * 
	 * @param tablecode
	 * @param newdata
	 * @param olddata
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public void updateData(String tablecode, Map newdata, Map olddata)
			throws BusinessException;

	/**
	 * Description : 根据冗余字段定义动态更新数据
	 * 
	 * @param rddDicColumn
	 * @param inputMap
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public void updateDataByRddDicColumn(DicColumn rddDicColumn, Map inputMap)
			throws BusinessException;

	/**
	 * Description : 根据表结构动态得到一条记录
	 * 
	 * @param tablecode
	 * @param inputMap
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public Map getDataByKey(String tablecode, Map inputMap)
			throws BusinessException;

	/**
	 * Description : 根据tablecode得到数据库字段定义
	 * 
	 * @param tablecode
	 * @return
	 * 
	 */
	public List<DicColumn> findDBDicColumnsByTablecode(String tablecode);

	/**
	 * Description : 检查表定义中关键字段的合法性
	 * 
	 * @param tablecode
	 * @param inputMap
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public void checkDicTableKeycolumns(String tablecode, Map inputMap)
			throws BusinessException;

	/**
	 * Description : 检查数据中是否有相同的编码
	 * 
	 * @param tablecode
	 * @param inputMap
	 * @throws BusinessException
	 * 
	 */
	@SuppressWarnings("unchecked")
	public void checkDataByCodeColumn(String tablecode, Map inputMap)
			throws BusinessException;

	/**
	 * Description : 缓存同步
	 * 
	 * @throws BusinessException
	 * 
	 */
	public void synchronizationCache() throws BusinessException;

	/**
	 * Description : 根据表编码得到表名sql
	 * 
	 * @param tablecode
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public String getTableNameSqlByTablecode(String tablecode)
			throws BusinessException;

	/**
	 * Description : 得到记录数
	 * 
	 * @param tablecode
	 * @param sql
	 * @return
	 * @throws BusinessException
	 * 
	 */
	public int getCount(String tablecode, String sql) throws BusinessException;
	
	/**
	 * 执行SQL
	 * @param tablecode
	 * @param sql
	 * @return
	 * @throws BusinessException
	 */
	public int updateData(String tablecode, String sql) throws BusinessException;
	
	
	
}